﻿using System;
using DDDSample.Application.Book;
using DDDSample.Application.PathFinder;
using DDDSample.Application.Routing;
using DDDSample.Domain.Cargo;
using DDDSample.Domain.Location;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DDDSample.Test.ApplicationTest
{
    [TestClass]
    public class BookServiceTestCasts : TestBase
    {
        public BookServiceTestCasts()
        {
            BuildSessionFactory();
        }

        [TestMethod]
        public void BookNewCargoTest1()
        {
            using (var session = SessionFactory.OpenSession())
            {
                var graphTraversalService = new GraphTraversalService(session);
                var routingService = new RoutingService(session, graphTraversalService);
                var bookService = new BookService(session, routingService);
                var origin = new UnLocode("CNHKG");
                var destination = new UnLocode("CNHGH");
                var id = bookService.BookNewCargo(origin, destination, DateTime.Now.AddDays(5));
                session.Flush();
                var cargo = session.Get<Cargo>(id);
                Assert.IsNotNull(cargo);
                Console.WriteLine(cargo.Id.ToString());
            }
        }

        [TestMethod]
        public void FindShortestPathsTest1()
        {
            using (var session = SessionFactory.OpenSession())
            {
                var id = Guid.Parse("b3bac762-e082-4c96-b0d4-5cdd6d7ae18b");
                var graphTraversalService = new GraphTraversalService(session);
                var routingService = new RoutingService(session, graphTraversalService);
                var bookService = new BookService(session, routingService);

                var routes = bookService.RequestPossibleRoutesForCargo(id);
                foreach (var route in routes)
                {
                    Console.WriteLine(route.InitialDepartureLocation.Name);
                    Console.WriteLine(route.FinalArrivalLocation.Name);
                }
            }
        }
    }
}